﻿using System;
using System.Runtime.Serialization;
using Microsoft.Kinect;

namespace TuDarmstadt.Informatik.TK.TnT.Captinect.Serializer
{
    [Serializable()]
    public class SerializableSkeletonFrame : ISerializable
    {

        public SerializableSkeletonFrame()
        {
        }

        public SerializableSkeletonFrame(SkeletonFrame frame)
        {
            FloorClipPlane = frame.FloorClipPlane;
            FrameNumber = frame.FrameNumber;
            SkeletonArrayLength = frame.SkeletonArrayLength;
            Timestamp = frame.Timestamp;
            TrackingMode = frame.TrackingMode;
            SkeletonData = new Skeleton[SkeletonArrayLength];
            frame.CopySkeletonDataTo(SkeletonData);
        }

        public SerializableSkeletonFrame(SerializationInfo info, StreamingContext context)
        {
            FloorClipPlane = (Tuple<float, float, float, float>)info.GetValue("FloorClipPlane", typeof(Tuple<float, float, float, float>));
            FrameNumber = info.GetInt32("FrameNumber");
            SkeletonArrayLength = info.GetInt32("SkeletonArrayLength");
            Timestamp = info.GetInt64("Timestamp");
            TrackingMode = (SkeletonTrackingMode)System.Enum.Parse(typeof(SkeletonTrackingMode), info.GetString("TrackingMode"));
            SkeletonData = (Skeleton[])info.GetValue("SkeletonData", typeof(Skeleton[]));
        }

        public Tuple<float, float, float, float> FloorClipPlane { get; set; }
        public int FrameNumber { get; private set; }
        public SkeletonTrackingMode TrackingMode { get; private set; }
        public int SkeletonArrayLength { get; private set; }
        public Skeleton[] SkeletonData { get; private set; }
        public long Timestamp { get; private set; }


        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("FloorClipPlane", FloorClipPlane);
            info.AddValue("FrameNumber", FrameNumber);
            info.AddValue("SkeletonArrayLength", SkeletonArrayLength);
            info.AddValue("Timestamp", Timestamp);
            info.AddValue("TrackingMode", TrackingMode.ToString());
            info.AddValue("SkeletonData", SkeletonData);
        }
    }
}
